// mixins.js
import toolBase from '../common/utils/tool.js';
import { LoginCenterApi } from '../api/serves';
import store from '../store';
import { ref, reactive, computed } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import route from '@/uni_modules/uv-ui-tools/libs/util/route.js';

export const useCounter = () => {
  const tool = toolBase.tool;
  onShow(() => {
    // #ifdef MP-WEIXIN
    uni.showShareMenu({});
    console.log(uni.getStorageSync('share_id'), 'share_id');

    if (!uni.getStorageSync('share_id')) {
      console.log(uni.getStorageSync('share_id'), '1231231');

      getUserInfo();
    }
    // #endif
  });
  const userInfo = computed(() => {
    return store.state.userInfo || tool.storage('userInfo');
  });
  const getUserInfo = async () => {
    const { code, data, msg } = await LoginCenterApi.user_detail();
    // if (code != 1) return tool.alert(msg);
    if (code != 1) return;
    store.commit('setUserInfo', data);
    tool.storage('userInfo', data);
    userInfo.value = data;
  };
  return {
    getUserInfo,
    userInfo,
    tool,
  };
};
